package anc.tankshooter.controls;

import org.andengine.entity.Entity;
import org.andengine.entity.primitive.Rectangle;
import org.andengine.util.color.Color;

import anc.tankshooter.models.Enermy;
import anc.tankshooter.ui.ResourcesManager;

public class BossHeartBar extends Entity {

	public static final float WIDTH=300f;
	public static final float HEIGHT=10f;
	public static final float PADDING=3f;
	
	private Rectangle mBox;
	private Rectangle mHeartBackgroundBar,mCurentHeartBar;
	private int mMaxHeart;
	private Enermy mEnermy;
	public BossHeartBar(Enermy e,float x,float y){
		super(x	, y);
		mEnermy = e;
		setMaxHeart(e.getHeart());
		
		mBox = new Rectangle(0, 0,WIDTH + 2*PADDING, HEIGHT + 2*PADDING , ResourcesManager.getInstance().mVertexManager);
		mBox.setColor(Color.BLACK);
		mBox.setAlpha(0.1f);
		
		mHeartBackgroundBar = new Rectangle(PADDING,PADDING ,WIDTH-PADDING*2,HEIGHT , ResourcesManager.getInstance().mVertexManager);
		mHeartBackgroundBar.setColor(Color.WHITE);
		mHeartBackgroundBar.setAlpha(0.3f);
		
		mCurentHeartBar = new Rectangle(PADDING,PADDING,WIDTH-PADDING*2,HEIGHT ,ResourcesManager.getInstance().mVertexManager);
		mCurentHeartBar.setColor(Color.GREEN);
		mCurentHeartBar.setAlpha(0.6f);
		
		attachChild(mBox);
		attachChild(mHeartBackgroundBar);
		attachChild(mCurentHeartBar);
	}
	
	@Override
	protected void onManagedUpdate(float pSecondsElapsed) {
		
		float percent =mMaxHeart<=0?0:mEnermy.getHeart()/(float)mMaxHeart;
		if(percent<=0.5f)
			mCurentHeartBar.setColor(Color.RED);
		else mCurentHeartBar.setColor(Color.GREEN);
		
		mCurentHeartBar.setWidth(percent*(WIDTH-PADDING*2));
		super.onManagedUpdate(pSecondsElapsed);
	}
	
	public int getMaxHeart() {
		return mMaxHeart;
	}

	public void setMaxHeart(int mMaxHeart) {
		this.mMaxHeart = mMaxHeart;
	}
}
